//
//  SYTableViewController.m
//  快医
//
//  Created by Eric on 16/7/7.
//
//

#import "SYTableViewController.h"

@interface SYTableViewController ()
@property(nonatomic, weak) UILabel *name;

@property(nonatomic, weak) UILabel *illness;

@property(nonatomic, weak) UIImageView *picture;

@property(nonatomic, weak) UIButton *status;

@end

@implementation SYTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.navigationItem.title = @"预约医生信息详情";
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName,nil]];

    
    
    [self setUpUI];
    
    [self setContents];
    
    [self didSelect];
    
}

-(void)setUpUI{
    
    self.view.backgroundColor = [UIColor whiteColor];

    UIImageView *pic = [[UIImageView alloc] init];
    
    pic.image = [UIImage imageNamed:@"banner"];

    self.picture = pic;
    
    [self.view addSubview:pic];
 
    [pic makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.offset(20);
        make.width.height.equalTo(60);
    }];

    UILabel *name = [[UILabel alloc] init];

    name.text =self.model.name;
    name.font = [UIFont systemFontOfSize:17];
    
    self.name = name;
    
    [self.view addSubview:name];
    
    [name makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.picture.top).offset(5);
        
        make.left.equalTo(self.picture.right).offset(10);
        
    }];
    


    UILabel *illness = [[UILabel alloc] init];
    
    self.illness = illness;
    
    illness.text = self.model.illness;
    
    illness.textColor = [UIColor lightGrayColor];
    
    [self.view addSubview:illness];
    
    [illness makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.name.top);
        
        make.left.equalTo(self.name.right).offset(10);
      
    }];
    
    UILabel *time = [[UILabel alloc] init];
    
    time.text = @"就诊:2016/06/19";
    
    time.textColor = [UIColor lightGrayColor];
    
    [self.view addSubview:time];
    
    [time makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.name.bottom).offset(10);
        
        make.left.equalTo(self.picture.right).offset(10);
        
    }];

    UIButton *illStatus = [[UIButton alloc] init];
    
    self.status = illStatus;
    
    self.status.layer.cornerRadius = 30;
    
    illStatus.enabled = NO;
    
    illStatus.backgroundColor = XHRThemeColor;
    
    if (self.model.status) {
        
         [illStatus setTitle:@"已就诊" forState:UIControlStateNormal];
        
    } else{
        [illStatus setTitle:@"审核中" forState:UIControlStateNormal];
    }
    illStatus.titleLabel.font = [UIFont systemFontOfSize:15];

    [self.view addSubview:illStatus];
    
    [illStatus makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.picture.top);
        
        make.right.offset(-20);
        
        make.width.height.equalTo(60);
        
    }];

    
    

}
- (void)setContents{

    UIImageView *line = [[UIImageView alloc] init];
    line.backgroundColor = [UIColor lightGrayColor];
    
    [self.view addSubview:line];
    
    [line makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.picture.bottom).offset(10);
        make.width.equalTo(375);
        make.height.equalTo(2);
 
    }];
    
    
    UILabel *appointDoc = [[UILabel alloc] init];
    
    appointDoc.text = @"预约医生:";
    appointDoc.textColor = [UIColor lightGrayColor];
    
    [self.view addSubview:appointDoc];
    
    [appointDoc makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(line.bottom).offset(10);
        make.left.offset(20);
        
    }];
    
    UIImageView *line1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 150, 375, 2)];
    line1.backgroundColor = [UIColor lightGrayColor];
    
    [self.view addSubview:line1];
    
    [line1 makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(appointDoc.bottom).offset(10);
        make.width.equalTo(XHRScreenWidth);
        make.height.equalTo(2);
        
        
    }];

    UILabel *doc = [[UILabel alloc] init];
    doc.text = @"马医生";
    doc.font = [UIFont systemFontOfSize:17];
 
    [self.view addSubview:doc];
    
    [doc makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(line1.bottom).offset(10);
        make.left.offset(20);
        
    }];
 
    UILabel *docMan = [[UILabel alloc] init];
    
    docMan.text = @"主任医生";
    
    docMan.textColor = [UIColor lightGrayColor];
    
    [self.view addSubview:docMan];
    
    [docMan makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(line1.bottom).offset(10);
        
        make.left.equalTo(doc.right).offset(20);
        
    }];

    UILabel *docAdr = [[UILabel alloc] init];
    
    docAdr.textColor = [UIColor lightGrayColor];
    docAdr.text = @"上海长征医院";
    
    [self.view addSubview:docAdr];
    
    [docAdr makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(doc.bottom).offset(10);
        make.left.offset(20);
   
    }];
    
    UIButton *bt = [[UIButton alloc] init];
    
    
    [bt setImage:[UIImage imageNamed:@"dijiaofankui"] forState:UIControlStateNormal];
    
    [self.view addSubview:bt];
    
    [bt makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(docMan.top).offset(5);
        
        make.right.offset(-20);
        make.height.offset(40);
        make.width.offset(70);
        
    }];
    
    UIImageView *line2 = [[UIImageView alloc] init];
    
    line2.backgroundColor = [UIColor lightGrayColor];
    
    [self.view addSubview:line2];
    
    [line2 makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(docAdr.bottom).offset(10);
        
        make.width.equalTo(XHRScreenWidth);
        make.height.equalTo(2);
        
        
    }];
    
    
    
    //预约须知
    
    UILabel *appointKN = [[UILabel alloc] init];
    
    appointKN.text = @"预约须知:";
    appointKN.textColor = [UIColor lightGrayColor];
    
    [self.view addSubview:appointKN];
    
    [appointKN makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(line2.bottom).offset(10);
        make.left.offset(20);
        
    }];
    
    UIImageView *line3 = [[UIImageView alloc] init];
    
    line3.backgroundColor = [UIColor lightGrayColor];
    
    [self.view addSubview:line3];
    
    [line3 makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(appointKN.bottom).offset(10);
        
        make.width.equalTo(XHRScreenWidth);
        make.height.equalTo(2);
        
        
    }];
    
    UIImageView *line4 = [[UIImageView alloc] init];
    
    line4.backgroundColor = [UIColor lightGrayColor];
    
    [self.view addSubview:line4];
    
    [line4 makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(line3.bottom).offset(105);
        
        make.width.equalTo(XHRScreenWidth);
        make.height.equalTo(2);
        
        
    }];
    
    
    

    UIView *view1 = [self contentsOfaMedAddr:@"就诊地点:" time:@"上海长征医院2楼心血管内科"];

    [self.view addSubview:view1];
    
    [view1 makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(line3.bottom).offset(0);
        make.left.right.offset(0);
        
        
        
    }];
//    [self group:line3 nextView:view1];
    
    UIView *view2 = [self contentsOfaMedAddr:@"取号时间:" time:@"9:00 - 10:00"];
    [self.view addSubview:view2];
    [self group:view1 nextView:view2];
    
    UIView *view3 = [self contentsOfaMedAddr:@"取号地址:" time:@"上海长征医院住院部"];
    [self.view addSubview:view3];
    [self group:view2 nextView:view3];
    
}

-(void)group:(UIView *)topV  nextView:(UIView *)nextV{

    [nextV makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(topV.bottom).offset(30);
        make.left.offset(0);
        make.trailing.offset(-5);
    }];

}


-(UIView *)contentsOfaMedAddr:(NSString *)medaddr  time:(NSString *)time {

    UIView *view = [[UIView alloc] init];
 
    UILabel *addr = [[UILabel alloc] init];
    addr.text = medaddr;
    addr.adjustsFontSizeToFitWidth = YES;
    
    UILabel *timer= [[UILabel alloc] init];
    
    timer.text = time;
    timer.textColor = [UIColor lightGrayColor];
    
    [view sizeToFit];
    
    [view addSubview:addr];
    [view addSubview:timer];
    
    [addr makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.offset(15);
//        make.trailing.offset(-5);
    }];
    
    [timer makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.top.equalTo(addr.top);
        make.left.equalTo(addr.right).offset(10);
        
    }];
    
    
    return view;
}

-(void)didSelect{
    
    UIButton *reSendMassage = [[UIButton alloc]init];
    
    [reSendMassage setBackgroundImage:[UIImage imageNamed:@"link_button_02"] forState:UIControlStateNormal];
    
    [reSendMassage setTitle:@"短信重发" forState:UIControlStateNormal];
    
    [reSendMassage setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    
    [self.view addSubview:reSendMassage];
    
    [reSendMassage makeConstraints:^(MASConstraintMaker *make) {
    
        make.bottom.offset(-30);
        make.left.offset(20);
        make.width.equalTo(self.view.bounds.size.width * 0.4);
        make.height.equalTo(40);
        
    }];
    
    
    
    UIButton *cancelSendMassage = [[UIButton alloc]init];
    
    [cancelSendMassage setBackgroundImage:[UIImage imageNamed:@"link_button_02"] forState:UIControlStateNormal];
    
    [cancelSendMassage setTitle:@"取消预约" forState:UIControlStateNormal];
    
    [cancelSendMassage setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [self.view addSubview:cancelSendMassage];
    
    [cancelSendMassage makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-30);
        make.right.offset(-20);
        make.width.equalTo(self.view.bounds.size.width * 0.4);
        make.height.equalTo(40);
    }];
    


}




@end
